package com.example.boot.service

import org.junit.jupiter.api.Test

class AssertTest {


    @Test
    fun buildPageRequest() {
//        val pageRequest = CursorPageRequest() // exp#1
//        val pageRequest = CursorPageRequest(first = 10, last = 20) // exp#2
//        val pageRequest = CursorPageRequest(first = 10) // pass
//        val pageRequest = CursorPageRequest(last = 10) // pass
//        val pageRequest = CursorPageRequest(first = -10) // exp#3
        val pageRequest = CursorPageRequest(last = -10) // exp#4
        println(pageRequest.first)
    }
}

data class CursorPageRequest(
    val first: Int? = null,
    val last: Int? = null,
) {
    init {
//        if (first == null && last == null) {
//            throw Exception("exp#1")
//        }
//        if (first != null && last != null) {
//            throw Exception("exp#2")
//        }
//        if (first != null && first < 0) {
//            throw Exception("exp#3")
//        }
//        if (last != null && last < 0) {
//            throw Exception("exp#4")
//        }

        require((first == null && last == null).not()) {
            throw Exception("exp#1")
        }
        require((first != null && last != null).not()) {
            throw Exception("exp#2")
        }
        require ((first != null && first < 0).not()) {
            throw Exception("exp#3")
        }
        require ((last != null && last < 0).not()) {
//        require (last != null && last >= 0) {
            throw Exception("exp#4")
        }

    }

}